<?php

namespace Common\Model;

use Think\Model;

class PhoneDescCombModel extends Model {
	
 
    /*检查机型存在*/
    public function checkModeldExist($modelID){
        return($this->where("modelID = $modelID")->count());
    }
    
    /*检查问题是否存在*/
    public function checkDescExist($descID){
        return($this->where("descID = $descID")->find());
    }
    
    /*删除机型原有问题*/
    public function deleteModel($modelID){
        $data = array(
            "isOn"=>0
        );
        $this->where("modelID = $modelID")->save($data);
    }
    
    /*插入数据*/
    public function addPhoneDescComb($data = ''){
           $rt = false;
        if ($this->create($data)) {
            $rt = $this->add();
        }
        return $rt;
    }
    
    /*从数据库中取得json数据*/
    public function getData($modelID){
        $data = array();
        $res = $this->where("modelID = $modelID")->field('brandID,modelID,descID,grade')->select();
        return $res;
    }
    
    /*得到机型的问题列表*/
    public function getCombDesc($modelID){
        $where = array(
            "pdc.modelID"=>$modelID,
            "pdc.isOn"=>1,
            "pd.isOn"=>1,
        );
        
        $pre =C("DB_PREFIX");
        $result = M("PhoneDescComb pdc")
                ->field("pdc.combID as PDCcombID,pdc.modelID as PDCmodelID,pdc.descID as PDCdescID,pdc.grade as PDCgrade,pdc.descPID as PDCdescPID,"
                        . "pd.desc as PDname,pd.pid as PDpid,pd.level as PDlevel")
                ->join("LEFT JOIN $pre"."phone_desc as pd on pdc.descID = pd.descID")
                ->order("PDCcombID asc")
                ->where($where)->select();
        
//        dump(M("PhoneDescComb pdc")->getLastSql());
        
        return $result;
    }
    
    /*得到分数*/
    public function getGrade($descID){
        $res = $this->where("descID = $descID")->find("grade");
    }
                 
}